local ROT = require 'lib.rotLua.src.rot'

local state = ROT.Class:extend()

function state:init(game, play)
    self.game = game
    self.play = play
    self.step = 24
end

function state:update()

    self.game.display:clear()

    local x, y, z = 0, 0, 0

    local count = 0
    local step = self.step
    
    for r = step, 255, step do
        x = x + 1
        y = 2
        z = 0
        for g = step, 255, step do
            y = y + 1
            z = 0
            for b = step, 255, step do
                local nz = z >= 5 and z - 5 or z
                local nw = z >= 5 and 11 or 0
                count = count + 1
                self.game.display:write('#', x + 11 * nz, y + nw, {r, g, b})
                z = z + 1
            end
        end
    end

    self.game.display:write(('%i color test (%i step)'):format(count, self.step), 1, 1)
end

function state:keypressed(key)
    local game = self.game

    if key == game.keys.move_n then
        self.step = self.step + 1
    elseif key == game.keys.move_s then
        self.step = self.step - 1
    elseif key == game.keys.scratch then game.state = self.play
    end

end

return state
